package 算法回顾;

/**
 * @description:
 * @author: 小白白
 * @create: 2021-09-18
 **/

public class No14最长公共前缀 {

    public String longestCommonPrefix(String[] strs) {

        StringBuilder result = new StringBuilder();
        for (int j = 0; j < strs[0].length(); j++) {
            char c = strs[0].charAt(j);
            for (int i = 1; i < strs.length; i++) {
                if ( j >= strs[i].length() || strs[i].charAt(j) != c) {
                    return result.toString();
                }
            }
            result.append(c);
        }

        return result.toString();
    }

}
